<template>

	<view class="home">
		<uni-search-bar @confirm="doSearch" v-model="key" />
	</view>
	<swiper style="height: 200px;" indicator-color="#fff" indicator-active-color="#ff6700" :indicator-dots="true"
		:autoplay="true" circular="" :interval="3000" :duration="1000">
		<swiper-item v-for="(item,index) in bannerGoodsList" :key="index">
			<view class="swiper-item">
				<image :src="item.goods_big_logo" style="width: 100%;" mode="widthFix"></image>
			</view>
		</swiper-item>
	</swiper>
	<view class="cateList">
		<view class="item" v-for="(item,index) in cateOneLst" :key="index">
			<image class="cate-img" :src="item.icon" mode="widthFix"></image>
			<view class="cate-name">{{item.name}}</view>
		</view>
	</view>
	<!-- 精选商品 -->
	     <view class="title">
	         精选商品
	     </view>
	     <view class="selectList">
	         <view class="item" v-for="item,index in selectedLst" :key="index">
	             <view class="pic">
	                 <image :src="item.goods_big_logo" mode=""></image>
	             </view>
	            
	                 <view class="name">{{item.name}}</view>
	                <!-- <view class="info">
	                     <text>￥{{item.price}}</text>
	                     <text class="tag">精选</text>
	                 </view> -->
					 <view class="msg">
						 <view class="price">￥{{item.price}}</view>
						 <view class="tag">精选</view>
					 </view>
	             </view>
	     </view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	let bannerGoodsList = ref([])
	let key = ref("")
	onLoad(() => {
		getBanner()
		getCateOneLst()
		getSelectedList()
	})

	function doSearch() {
		uni.showToast({
			title: key.value,
		})
	}


	async function getBanner() {
		let res = await uni.$post("/goodsPromoteSelect", {
			"is_selected": 1, //精选商品
			"is_promote": 0,
			"page": 1, //第一页
			"number": 5
		})

		if (res.code == 200) {
			bannerGoodsList.value = res.goodsList.map(item => {
				item.goods_big_logo = uni.$base_url + item.goods_big_logo
				return item
			})
		}
		// console.log(bannerGoodsList.value)
		// console.log(res);
	}
	// getBanner()
	const cateOneLst = ref([])
	async function getCateOneLst() {
		let res = await uni.$post("/categoryListLevel", {
			"level": 0
		})
		// console.log(res)
		if (res.code == 200) {
			cateOneLst.value = res.result.map(item => {
				item.icon = uni.$base_url + item.icon
				return item
			})
		}
		// console.log(cateOneLst.value)
	}

	const selectedLst = ref([])
	async function getSelectedList() {
		let res = await uni.$post("/goodsPromoteSelect", {
			"is_selected": 1, //精选商品
			"is_promote": 0,
			"page": 1, //第一页
			"number": 20
		})
		// console.log(res);
		if (res.code == 200) {
			selectedLst.value = res.goodsList.map(item => {
				item.goods_big_logo = uni.$base_url + item.goods_big_logo
				return item
			})
		}
		console.log(cateOneLst.value);
	}
</script>

<style>
	.cateList {
		display: flex;
		justify-content: space-around;
		background-color: #fff;
		margin: 10rpx 0 10rpx 0;
	}

	/* 每个商品分类 */
	.cateList>.item {
		width: 130rpx;
		height: 130rpx;
		/* border:1px solid red; */
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: 20rpx;

	}

	/* 商品分类中图片 */
	.cateList>.item>.cate-img {
		width: 60rpx;
		height: 60rpx;
		margin-top: 20rpx;
	}
	/* 精品商品样式 */
	.selectList{
		display: flex;
		/* 换行 */
		flex-wrap: wrap;
		justify-content: space-around;
	}
	.selectList>.item{
		width: 350rpx;
		/* 修改盒子模型计算方式 */
		box-sizing: border-box;
		padding: 15rpx;
		border: 1rpx solid #eee;
		box-shadow: 3px 3px 3px #eee;
	}
	.selectList>.item>.pic{
		width: 100%;
		height: 320rpx;
		border: 1px solid #ccc;
		
	}
	.selectList>.item>.pic>image{
		width: 100%;
		height: 100%;
	}
	.selectList>.item>.name{
		 overflow: hidden;
		 -webkit-line-clamp: 2;  
		 text-overflow: ellipsis;
		 display: -webkit-box;
		 -webkit-box-orient: vertical;
		 color: #666;
		 font-size: 14px;
	}
	.selectList>.item>.msg{
		display: flex;
		justify-content: space-between;
	}
	.selectList>.item>.msg>.price{
		color: #ff6700;
	}
	.selectList>.item>.msg>.tag{
		background-color: #ff6700;
		color: #fff;
		font-size: 12px;
		padding: 2px 3px;
		border-radius: 5px;
	}
</style>